/**
  ******************************************************************************
  * @file    task_cfg.h 
  * @author  Feirui_Joe
  * @version V0.1
  * @date    07/26/2010
  * @brief   OS Task and Event Management
  ******************************************************************************
  * @copy
  *
  * <h2><center>&copy; COPYRIGHT 2010 Feirui</center></h2>
  */ 

#ifndef  __TASK_CFG_H__
#define  __TASK_CFG_H__


#ifdef __cplusplus
 extern "C" {
#endif

/**
  * @brief  Tasks Management.
  */
/*$PAGE*//**
  * @brief  INCLUDE FILES.
  */
//#include <includes.h>
#include "app_boot.h"
#include "app_Timer.h"
#include "app_start.h"
#include "app_acad.h"
#include "app_network.h"
#include "app_pid.h"
#include "app_communi.h"
#include "app_alarm.h"
#include "app_relay.h"
#include "app_dstin.h"

/**
  * @brief  Debug Test
  */
#ifdef DISABLE_DEBUG_OPT
#define SYS_DebugERROR                      
#else
#define SYS_DebugERROR       SysDebug_Handler()
#endif

#define TimeDlyInfinity      ((uint32_t)0)



/*$PAGE*/
#define TaskStartSyncNumber   7

                 /**************TASK define******************/

                              /* Priority */
/**
  * @brief TASK PRIORITIES definition
  */
/* #define  OS_TASK_Idle_PRIO               (OS_LOWEST_PRIO - 0)   */
/* #define  OS_TASK_Stat_PRIO               (OS_LOWEST_PRIO - 1)   */
/* #define  Reserve4_PRIO                   (OS_LOWEST_PRIO - 2)   */

// #define  OS_TASK_TMR_PRIO                   11
#define  APP_TASK_PRIO_NETFLOW                 7        /* NetWork Task         */
#define  APP_TASK_PRIO_NETPARSE                8        /* NetWork Parse Task         */
#define  APP_TASK_PRIO_NETHANDLE               9        /* NetWork Handle Task         */
#define  APP_TASK_PRIO_START                   12        /* Memory Task        */
#define  APP_TASK_PRIO_WORKFLOW                14        
#define  APP_TASK_PRIO_ACAD                    4        /* AC AD Task         */
#define  APP_TASK_PRIO_PID                     5        /* PID Task         */
#define  APP_TASK_PRIO_COMMUNI                 10        /* Communication Task */
#define  APP_TASK_PRIO_ALARM                   15        /* Communication Task */
#define  APP_TASK_PRIO_RS485Handle             16        /* RS485 Communication Task */
#define  APP_TASK_PRIO_RELAY                   17        /* Relay Task         */
#define  APP_TASK_PRIO_DSTIN                   18        /* Digital Input Task */



/* #define  Reserve2_PRIO                    2       */
/* #define  Reserve1_PRIO                    1       */
/* #define  Reserve0_PRIO                    0       */

                              /* TASK STACK */
/**
  * @brief TASK STACK SIZES definition
  *        Size of the task stacks (# of OS_STK entries)
  */
#define  APP_TASK_STK_SIZE_START                         260
#define  APP_TASK_STK_SIZE_WORKFLOW                      280
#define  APP_TASK_STK_SIZE_ACAD                          260
#define  APP_TASK_STK_SIZE_PID                           260
#define  APP_TASK_STK_SIZE_NETFLOW                       260
#define  APP_TASK_STK_SIZE_NETPARSE                      260
#define  APP_TASK_STK_SIZE_NETHANDLE                     260
#define  APP_TASK_STK_SIZE_COMMUNI                       260
#define  APP_TASK_STK_SIZE_ALARM                         260
#define  APP_TASK_STK_SIZE_RS485HANDLE                   260
#define  APP_TASK_STK_SIZE_RELAY                         170
#define  APP_TASK_STK_SIZE_DSTIN                         170


/**
  * @brief STACK definition
  */
APP_EXT_START     OS_STK App_TaskStk_START[APP_TASK_STK_SIZE_START];
APP_EXT_ACAD      OS_STK App_TaskStk_ACAD [APP_TASK_STK_SIZE_ACAD];
APP_EXT_PID       OS_STK App_TaskStk_PID  [APP_TASK_STK_SIZE_PID];
APP_EXT_NETWORK   OS_STK App_TaskStk_NETFLOW   [APP_TASK_STK_SIZE_NETFLOW];
APP_EXT_NETWORK   OS_STK App_TaskStk_NETPARSE  [APP_TASK_STK_SIZE_NETPARSE];
APP_EXT_NETWORK   OS_STK App_TaskStk_NETHANDLE [APP_TASK_STK_SIZE_NETHANDLE];
APP_EXT_START OS_STK App_TaskStk_WORKFLOW[APP_TASK_STK_SIZE_WORKFLOW];
APP_EXT_COMMUNI   OS_STK App_TaskStk_COMMUNI[APP_TASK_STK_SIZE_COMMUNI];
APP_EXT_ALARM   OS_STK App_TaskStk_Alarm[APP_TASK_STK_SIZE_ALARM];
APP_EXT_ALARM   OS_STK App_TaskStk_RS485Handle[APP_TASK_STK_SIZE_RS485HANDLE];
APP_EXT_RELAY     OS_STK    App_TaskStk_RELAY   [APP_TASK_STK_SIZE_RELAY   ];
APP_EXT_DSTIN     OS_STK    App_TaskStk_DSTIN   [APP_TASK_STK_SIZE_DSTIN   ];

                              /* TASK function */
/**
  * @brief Task definition
  */
APP_EXT_START void App_Task_START(void *p_arg);
APP_EXT_START void App_Task_WORKFLOW(void *p_arg);
APP_EXT_ACAD  void App_Task_ACAD(void *p_arg);
APP_EXT_PID   void App_Task_PID(void *p_arg);
APP_EXT_NETWORK   void App_Task_NetWork_Flow(void *p_arg);
APP_EXT_NETWORK   void App_Task_NetWork_Parse(void *p_arg);
APP_EXT_NETWORK   void App_Task_NetWork_Handle(void *p_arg);
APP_EXT_COMMUNI void App_Task_COMMUNI(void *p_arg);
APP_EXT_ALARM void App_Task_Alarm(void *p_arg);
APP_EXT_RELAY    void  App_Task_RELAY   (void *p_arg);
APP_EXT_DSTIN     void  App_Task_DSTIN   (void *p_arg);


/*$PAGE*/                      /**************EVENT******************/

/**
  * @brief EVENT definition
  */

                                  /* Sem x23 */
  /* EVENT--Sem definition*/
APP_EXT_START    OS_EVENT           *App_Sem_STARTSYNC;
APP_EXT_START    OS_EVENT           *App_Sem_WORKFLOWCMD;
APP_EXT_START    OS_EVENT           *App_Sem_NETWORKTX;
APP_EXT_START    OS_EVENT           *App_Sem_SRAMRC;
APP_EXT_START    OS_EVENT           *App_Sem_EEPROMRC;
APP_EXT_START    OS_EVENT           *App_Sem_RS485TC;
APP_EXT_START    OS_EVENT           *App_Sem_RS232TC;
APP_EXT_START    OS_EVENT           *App_Sem_RS485BUSIDLE;
APP_EXT_START    OS_EVENT           *App_Sem_PMOTORRC;
APP_EXT_START    OS_EVENT           *App_Sem_TEMPCTLRC;
APP_EXT_START    OS_EVENT           *App_Sem_RTCADJ;
APP_EXT_START    OS_EVENT           *App_Sem_DATABASERW;
APP_EXT_START    OS_EVENT           *App_Sem_NETWORKTEST;
APP_EXT_START    OS_EVENT           *App_Sem_MOMERYEE;
APP_EXT_START    OS_EVENT           *App_Sem_WORKFLOW;
APP_EXT_START    OS_EVENT           *App_Sem_OUTPUTS;
APP_EXT_START    OS_EVENT           *App_Sem_OPERATE;   // 操作互斥信号量


APP_EXT_START    OS_EVENT           *App_Sem_DBPAGE0;
APP_EXT_START    OS_EVENT           *App_Sem_DBPAGE1;
APP_EXT_START    OS_EVENT           *App_Sem_DBPAGE2;
APP_EXT_START    OS_EVENT           *App_Sem_DBPAGE3;
APP_EXT_START    OS_EVENT           *App_Sem_DBPAGE4;
APP_EXT_START    OS_EVENT           *App_Sem_DBPAGE5;
APP_EXT_START    OS_EVENT           *App_Sem_DBPAGE6;
APP_EXT_START    OS_EVENT           *App_Sem_DBPAGE7;
APP_EXT_START    OS_EVENT           *App_Sem_DBPAGE8;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE0;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE1;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE2;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE3;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE4;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE5;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE6;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE7;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE8;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE9;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE10;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE11;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE12;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE13;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE14;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE15;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE16;
APP_EXT_START    OS_EVENT           *App_Sem_CFGPAGE17;
APP_EXT_START    OS_EVENT           *App_Sem_TMPPAGE0;
APP_EXT_START    OS_EVENT           *App_Sem_TMPPAGE1;




/* EVENT--Mbox definition*/





/* EVENT--Flag definition*/
APP_EXT_START    OS_FLAG_GRP        *App_Flags_ACAD;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_NETWORK;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_NETPARSE;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_WORKFLOW;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_PID;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_COMMON;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_RS485Handle;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_COMMUNI;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_Alarm;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_RELAY   ;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_DSTIN   ;




  /* EVENT--Q definition*/
APP_EXT_START     OS_EVENT          *App_Q_ACAD;
APP_EXT_START     OS_EVENT          *App_Q_NETHANDLE;


                                  /* Tmr */
/**
  * @brief Tmr definition
  */
APP_EXT_START     OS_TMR            *App_Tmr_TIMER01HZ;
APP_EXT_START     OS_TMR            *App_Tmr_TIMER05HZ;
APP_EXT_START     OS_TMR            *App_Tmr_TIMER10HZ;
APP_EXT_START     OS_TMR            *App_Tmr_TIMER20HZ;
APP_EXT_START     OS_TMR            *App_Tmr_TIMER40HZ;




/**************Name******************/

/**
  * @brief TASKS/EVENT NAMES definition
  */
                              /* Task Name    */
#define  APP_TASK_NAME_START                       "STR_T"
#define  APP_TASK_NAME_ACAD                        "ACAD_T"
#define  APP_TASK_NAME_PID                         "PID_T"
#define  APP_TASK_NAME_NETFLOW                     "NETFLOW_T"
#define  APP_TASK_NAME_NETPARSE                    "NETPARSE_T"
#define  APP_TASK_NAME_NETHANDLE                   "NETHANDLE_T"
#define  APP_TASK_NAME_COMMUNI                     "COMMUNI_T"
#define  APP_TASK_NAME_ALARM                     "ALARM_T"
#define  APP_TASK_NAME_RELAY                     "RELAY_T"
#define  APP_TASK_NAME_DSTIN                     "DSTIN_T"


                              /* MBOX Name    */


                              /* SEM Name     */
#define  App_SEM_NAME_STARTSYNC              "STARTSYNC_S"
#define  App_SEM_NAME_NETWORKTX              "NETWORKTX_S"
#define  App_SEM_NAME_SRAMRC                 "SRAMRC_S"
#define  App_SEM_NAME_EEPROMRC               "EEPROMRC_S"
#define  App_SEM_NAME_RS485TC                "RS485TC_S"
#define  App_SEM_NAME_RS232TC                "RS232TC_S"
#define  App_SEM_NAME_RS485BUSIDLE           "RS485IDLE_S"
#define  App_SEM_NAME_PMOTORRC               "PMOTORRC_S"
#define  App_SEM_NAME_TEMPCTLRC              "PMOTORRC_S"
#define  App_SEM_NAME_RTC                    "RTC_S"
#define  App_SEM_NAME_DATABASERW             "DATABASERW_S"
#define  App_SEM_NAME_TIMEOUTHANDLE          "TIMEOUTHANDLE_S"
#define  App_SEM_NAME_NETWORKTEST            "NETWORKTEST_S"
#define  App_SEM_NAME_MEMOTYEE               "MEMORYEE_S"

#define  App_SEM_NAME_DBPAGE0                "DBPAGE0_S"
#define  App_SEM_NAME_DBPAGE1                "DBPAGE1_S"
#define  App_SEM_NAME_DBPAGE2                "DBPAGE2_S"
#define  App_SEM_NAME_DBPAGE3                "DBPAGE3_S"
#define  App_SEM_NAME_DBPAGE4                "DBPAGE4_S"
#define  App_SEM_NAME_DBPAGE5                "DBPAGE5_S"
#define  App_SEM_NAME_DBPAGE6                "DBPAGE6_S"
#define  App_SEM_NAME_DBPAGE7                "DBPAGE7_S"
#define  App_SEM_NAME_DBPAGE8                "DBPAGE8_S"
#define  App_SEM_NAME_CFGPAGE0               "CFGPAGE0_S"
#define  App_SEM_NAME_CFGPAGE1               "CFGPAGE1_S"
#define  App_SEM_NAME_CFGPAGE2               "CFGPAGE2_S"
#define  App_SEM_NAME_CFGPAGE3               "CFGPAGE3_S"
#define  App_SEM_NAME_CFGPAGE4               "CFGPAGE4_S"
#define  App_SEM_NAME_CFGPAGE5               "CFGPAGE5_S"
#define  App_SEM_NAME_CFGPAGE6               "CFGPAGE6_S"
#define  App_SEM_NAME_CFGPAGE7               "CFGPAGE7_S"
#define  App_SEM_NAME_CFGPAGE8               "CFGPAGE8_S"
#define  App_SEM_NAME_CFGPAGE9               "CFGPAGE9_S"
#define  App_SEM_NAME_CFGPAGE10              "CFGPAGE10_S"
#define  App_SEM_NAME_CFGPAGE11              "CFGPAGE11_S"
#define  App_SEM_NAME_CFGPAGE12              "CFGPAGE12_S"
#define  App_SEM_NAME_CFGPAGE13              "CFGPAGE13_S"
#define  App_SEM_NAME_CFGPAGE14              "CFGPAGE14_S"
#define  App_SEM_NAME_CFGPAGE15              "CFGPAGE15_S"
#define  App_SEM_NAME_CFGPAGE16              "CFGPAGE16_S"
#define  App_SEM_NAME_CFGPAGE17              "CFGPAGE17_S"
#define  App_SEM_NAME_TMPPAGE0               "TMPPAGE0_S"
#define  App_SEM_NAME_TMPPAGE1               "TMPPAGE1_S"


                              /* FLAGS Name   */
#define  App_FLAGS_NAME_ACAD                    "ACAD_Fl" 
#define  App_FLAGS_NAME_WIFI                    "WIFI_Fl" 
#define  App_FLAGS_NAME_NETPARSE                "PARSE_Fl" 
#define  App_FLAGS_NAME_COMMON                  "COMM_Fl" 
#define  App_FLAGS_NAME_RS485Handle              "COMM_Fl" 
#define  App_FLAGS_NAME_PID                      "PID_Fl" 
#define  App_FLAGS_NAME_COMMUNI                  "COMMUNI_Fl" 


                              /* Q Name       */
#define  App_Q_NAME_ACAD                         "ACAD_Q"
#define  App_Q_NAME_NETHANDLE                    "NETHANDLE_Q"

APP_EXT_START     void              *ACRecdataMsg[ACADRecdataQNum];
APP_EXT_START     void              *DataHandleMsg[NetDataHandleQNum];

                              /* TMR Name     */
#define  App_TMR_NAME_TIMER01HZ                   "1HZ_Tr"   
#define  App_TMR_NAME_TIMER05HZ                   "5HZ_Tr"   
#define  App_TMR_NAME_TIMER10HZ                   "10HZ_Tr"   
#define  App_TMR_NAME_TIMER20HZ                   "20HZ_Tr"   
#define  App_TMR_NAME_TIMER100HZ                  "100HZ_Tr"   
   



/*$PAGE*/#ifdef __cplusplus
}
#endif


#endif	/*	__TASK_CFG_H__	*/
